// debounce N 秒内只执行一次, 如果N秒内事件再次触发, 则会重新计算时间
// function debounce(fn, delay) {
//     let timer = null;
//     return (args) => {
//         if (timer) {
//             clearTimeout(timer)
//         }
//         timer = setTimeout(() => {
//             fn(...args)
//         }, delay);
//     }
// }


//  时间戳版的防抖
function debounce(fn, delay) {
    let prevTime = 0;
    return function () {
        let args = arguments;
        let now = new Date().getTime();
        if (now - prevTime < delay) {
            prevTime = now;
            return
        }
        fn(args)
    }
}